-
Notifications
You must be signed in to change notification settings - Fork 55
Add dataUri and dataUriToString functions
#1332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add dataUri and dataUriToString functions
#1332
Conversation
| ) | ||
| })?; | ||
|
|
||
| let result = String::from_utf8(decoded_bytes).map_err(|_| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can assume utf8 since the charset is part of the URI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should the function check? If a charset is specified in the URI and error if it's not UTF-8? Do we need to support other charsets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if not specified, we can assume utf-8 since it's prevalent, but if the value is something else (like utf-16), we can just error saying it's not supported for now. We can add more charset support in the future based on user feedback.
| @{ expression = "[dataUriToString('not a data uri')]" ; expectedError = 'Invalid data URI format' } | ||
| @{ expression = "[dataUriToString('data:text/plain;base64')]" ; expectedError = 'Invalid data URI format' } | ||
| @{ expression = "[dataUriToString('data:;base64,invalid!@#')]" ; expectedError = 'Invalid base64 encoding' } | ||
| @{ expression = "[dataUriToString('data:text/plain;charset=utf-16;base64,SGVsbG8=')]" ; expectedError = 'Unsupported charset' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a few more tests:
double-colon: data::text/plain;base64,
double-semi-colon: data:text/plain;;base64,
double-char-set: data:text/plain;charset=utf-8;charset=utf-8,base64,
double-comma: data:text/plain;base64,,
invalid-property: data:text/plain;foo=bar;base64,
PR Summary
This pull request adds the
dataUrianddataUriToStringfunctions, including tests and documentation.PR Context
Partially addresses #57.